Python Forum

Full Version: HELP on Unwanted CSV Export Output | Using Selenium to Scrape
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

It's been a long time since my last post.

Anyway, I'm having trouble with the CSV export result on a website I am trying to scrape data from.

====================================

Output Problems:
Output in column but just the first column and it only output's the first column of data
[Image: b6Qhek6.png]

Output in rows but just one row
[Image: Imhh7HQ.png]

I just want it to output the typical way
[Image: Vmp6MHp.png]

====================================
Here's a segment of the whole site's html where my particular target is:
# My apology, I do not know how to wrap html in creating a thread and the button "Insert code snippet" doesn't work.
<tbody id="sitesList">
	<tr data-value="11230" class="item-row">
		<td class="text-left"><a href="http://www.example.com" target="_blank">example.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11230.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>92</td>
		<td>71</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Education
			<br>Family &amp; Parenting
			<br>Food &amp; Drink
			<br>
		</td>
		<td>Included</td>
		<td><strong>$1</strong></td>
		<td><span data-id="11230" class="btn btn-success btn-sm addtocart">Buy Website $1</span></td>
	</tr>
	<tr data-value="11229" class="item-row">
		<td class="text-left"><a href="http://example1.com/" target="_blank">example1.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11229.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>65</td>
		<td>34</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Business &amp; Finance
			<br>General: Multi-Niche
			<br>
		</td>
		<td>Included</td>
		<td><strong>$2</strong></td>
		<td><span data-id="11229" class="btn btn-success btn-sm addtocart">Buy Website $2</span></td>
	</tr>
	<tr data-value="11228" class="item-row">
		<td class="text-left"><a href="https://example2.com" target="_blank">example2.com</a> <i class="fa fa-external-link"></i>
			<div class="tooltip owner_tooltip" style="float: right;opacity: 1;width: 20px;height: 20px;background-size: 100%;"><span class="tooltiptext">Owner Verified</span></div>
			<br><span>» <a href="https://www.domain.com/site/11228.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>27</td>
		<td>26</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Cryptocurrency
			<br>
		</td>
		<td>Not Included</td>
		<td><strong>$3</strong></td>
		<td><span data-id="11228" class="btn btn-success btn-sm addtocart">Buy Website $3</span></td>
	</tr>
	<tr data-value="11227" class="item-row">
		<td class="text-left"><a href="https://example3.com" target="_blank">example3.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11227.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>23</td>
		<td>29</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Business &amp; Finance
			<br>Health
			<br>SEO &amp; Digital Marketing
			<br>
		</td>
		<td>Included</td>
		<td><strong>$4</strong></td>
		<td><span data-id="11227" class="btn btn-success btn-sm addtocart">Buy Website $4</span></td>
	</tr>
</tbody>
====================================

I'm using selenium and here's my code:
siteList_tds = driver.find_elements(By.XPATH, "//tbody[@id='sitesList']//tr//td")
with open('test.csv', 'w') as f:
    write = csv.writer(f)
    for s in siteList_tds:
        write.writerow(s.text) ## or write.writerow([s.text])